﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PPI.Client;
using PPI.Client.Interface;
using PPI.Client.Presenter;
using PPI.Entities;

namespace PPI
{
    public partial class frmFilterBrowser : frmBase,IFilterBrowser,IFilterType
    {
        private string m_direction;
        private ECentralOffice m_SelectedOffice;
        private EBasePosition m_SelectedVisit;
        private string m_connectionString;
        private FilterBrowserPresenter m_Presenter;

        public frmFilterBrowser()
        {
            InitializeComponent();
            this.MenuMain.Visible = false;
            m_Presenter = new FilterBrowserPresenter(this);
        }

        public string Direction
        {
            get { return m_direction; }
            set { m_direction = value; }
        }

        public ECentralOffice SelectedOffice
        {
            get {return m_SelectedOffice; }
        }

        public string VisitType
        {
            get { return ddlVisitType.Text; }
        }

        public int SelectedId
        {
            get { return txtVisitId.Value; }
        }

        public EBasePosition SelectedVisit
        {
            get { return m_SelectedVisit; }
            set { m_SelectedVisit = value; }
        }

        public string ConnectionString
        {
            get { return m_connectionString; }
            set { m_connectionString = value; }
        }

        private void frmFilterBrowser_Load(object sender, EventArgs e)
        {
            LoadCombos();
        }

        private void LoadCombos()
        {
            ddlVisitType.Items.Add("GPS Structure");
            ddlVisitType.Items.Add("GPS Pole");
            ddlVisitType.Items.Add("Inspection Structure");
            ddlVisitType.Items.Add("Inspection Pole");
            ddlVisitType.Items.Add("Asset");

            ddlHQ.ValueMember = "Address";
            ddlHQ.DisplayMember = "Name";
            ddlHQ.DataSource = LCacheDataSingleton.Instance.CentralOffices;

        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            m_Presenter.Search();
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void ddlHQ_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlHQ.SelectedItem is ECentralOffice)
            {
                m_SelectedOffice = (ECentralOffice)ddlHQ.SelectedItem;
            }
            
        }
    }
}
